using System;
using System.Collections.Generic;
using System.Text;
using SMS.Common;
using SMS.Framework;
using System.Windows.Forms;

namespace SMS.SalesManagement
{
    public class OperationLogWindow : IMdiChildWindow
    {
        OperationLogForm operationLogForm = null;
        public OperationLogWindow()
        {
            Context.Current.OnApplicationCommand += new OnApplicationCommandEventHandler(OnApplicationCommand);
        }


        #region IMdiChildWindow Members

        public void Activate()
        {
            if (IsInstanced())
            {
                operationLogForm.WindowState = FormWindowState.Maximized;
                operationLogForm.Visible = true;
            }
        }

        public bool CanClosed()
        {
            if (IsInstanced())
            {
                return true;
            }
            return false;
        }

        public bool IsInstanced()
        {
            if (operationLogForm == null || operationLogForm.IsDisposed)
            {
                return false;
            }
            return true;
        }

        #endregion

        #region IWindow Members

        public void CloseWindow()
        {
            if (IsInstanced())
            {
                operationLogForm.Close();
                operationLogForm.Dispose();
            }
        }

        public bool Init()
        {
            try
            {
                if (!IsInstanced())
                {
                    operationLogForm = new OperationLogForm();
                }
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }

        public bool OnApplicationCommand(object sender, string commandName, object[] commandParameters)
        {
            switch (commandName.Trim().ToLower())
            {
                case "showmdisalesoperationlogwindow":
                    ShowWindow();
                    break;
                default:
                    break;
            }
            return false;
        }

        public void ShowWindow()
        {
            if (Init())
            {
                operationLogForm.MdiParent = Context.Current.MdiWindow.GetWindow();
                operationLogForm.WindowState = FormWindowState.Maximized;
                operationLogForm.Show();
            }
        }

        #endregion
    }
}
